package com.gome.ss.core.plugin;

import java.util.ArrayList;
import java.util.List;

import com.mongodb.DBObject;

public class SpiderLocalPluginConfig {
	
	private String name;
	private String desc;
	private int maxThreadCount = 10;
	private int scheduleInterval = -1;
	private String callbackLink = "";
	private List<SpiderLocalPluginStepConfig> steps = new ArrayList<SpiderLocalPluginStepConfig>();
	
	public SpiderLocalPluginConfig(DBObject configObj) {
		this.name = (String) configObj.get("name");
		this.desc = (String) configObj.get("desc");
		if (configObj.get("maxThreadCount") != null) {
			String maxThreadCountString = (String) configObj.get("maxThreadCount");
			maxThreadCount = Integer.valueOf(maxThreadCountString);
		}
		
		if (configObj.get("callbackLink") != null) {
			this.callbackLink = (String) configObj.get("callbackLink");
		}
		
		if (configObj.get("scheduleInterval") != null) {
		    String intervalStr = (String) configObj.get("scheduleInterval");
			this.scheduleInterval = Integer.valueOf(intervalStr);
		}
		
		List<DBObject> stepObjs = (List<DBObject>) configObj.get("steps");
		
		String keyWord = "";
		if (configObj.get("keyWord") != null)
			keyWord = (String) configObj.get("keyWord");
		
		for (DBObject so : stepObjs) {
			SpiderLocalPluginStepConfig stepConfig = new SpiderLocalPluginStepConfig(name, callbackLink, so);
			stepConfig.setKeyWord(keyWord);
			this.steps.add(stepConfig);
		}
	}

	public String getName() {
		return name;
	}

	public String getDesc() {
		return desc;
	}

	public int getMaxThreadCount() {
		return maxThreadCount;
	}

	public List<SpiderLocalPluginStepConfig> getSteps() {
		return steps;
	}

	public int getScheduleInterval() {
		return scheduleInterval;
	}
}
